<?php

namespace App\Models\video;

class CommonServer
{
    public static function judgeUpIdentity($userId, $mallId){
        $broadcasterData = BroadcasterModel::query()->from(BroadcasterModel::query()->getModel()->getTable()." as b")
            ->leftJoin(BroadcasterRelationModel::query()->getModel()->getTable()." as br", "b.id", "=", "br.broadcaster_id")
            ->select("b.id")
            ->where(["b.status" => 1, "b.mall_id" => $mallId, "br.user_id" => $userId])
            ->first();
        if(empty($broadcasterData->id)){
            return false;
        }
        return $broadcasterData->id;
    }

    static function price_format($val, $returnType = 'string', $decimals = 2)
    {
        $val = floatval($val);
        $result = number_format($val, $decimals, '.', '');
        if ($returnType === 'float') {
            return (float)$result;
        }
        return $result;
    }

    static function getUrl($route = '', $w = true){
        global $scf_data;
        if($route) {
            $route = "/" . ltrim($route, "/");
        }
        if(empty($scf_data)) {
            if($w && basename($_SERVER["DOCUMENT_ROOT"]) != "public") { // 根目录运行
                $url = request()->getSchemeAndHttpHost()."/public{$route}";
            }else{
                $url = request()->getSchemeAndHttpHost().$route;
            }
        }else{
            $url = $scf_data["host"].$route;
        }
        return $url;
    }
}